<template>
  <div class="content">
    <div ref="main" style="width: 600px;height:400px;"></div>
  </div>
</template>

<script>
import Echarts from 'echarts'

export default {
  mounted() {
    this.getechartsdata()
  },

  methods: {
    getechartsdata() {
      const myChart = Echarts.init(this.$refs.main)
      const option = {
        backgroundColor: '#eee',
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            lineStyle: {
              color: {
                type: 'linear',
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                colorStops: [
                  {
                    offset: 0,
                    color: 'rgba(0, 255, 233,0)'
                  },
                  {
                    offset: 0.5,
                    color: 'rgba(255, 255, 255,1)'
                  },
                  {
                    offset: 1,
                    color: 'rgba(0, 255, 233,0)'
                  }
                ],
                global: false
              }
            }
          }
        },
        legend: {
          x: '46%',
          top: '5%',
          textStyle: {
            color: '#000'
          },
          data: ['订单统计', '销量统计']
        },
        grid: {
          top: '15%',
          left: '5%',
          right: '5%',
          bottom: '15%'
          // containLabel: true
        },
        xAxis: [
          {
            type: 'category',

            axisLine: {
              lineStyle: {
                color: '#000'
              }
            },
            splitLine: {
              show: false
            },
            axisTick: {
              show: false
            },
            data: []
          }
        ],
        yAxis: [
          {
            type: 'value',
            axisLine: {
              show: true,
              lineStyle: {
                color: '#000'
              }
            }
          }
        ],
        series: [
          {
            name: '订单统计',
            type: 'line',
            smooth: true, // 是否平滑
            showAllSymbol: true,
            symbol: 'circle',
            symbolSize: 25,
            lineStyle: {
              normal: {
                color: '#32c5e9',
                shadowColor: 'rgba(0, 0, 0, .3)',
                shadowBlur: 0,
                shadowOffsetY: 5,
                shadowOffsetX: 5
              }
            },
            label: {
              show: true,
              position: 'top',
              textStyle: {
                color: '#6c50f3'
              }
            },
            itemStyle: {
              color: '#37a2da',
              borderColor: '#fff',
              borderWidth: 3,
              shadowColor: 'rgba(0, 0, 0, .3)',
              shadowBlur: 0,
              shadowOffsetY: 2,
              shadowOffsetX: 2
            },
            tooltip: {
              show: false
            },
            areaStyle: {
              normal: {
                color: new Echarts.graphic.LinearGradient(
                  0,
                  0,
                  0,
                  1,
                  [
                    {
                      offset: 0,
                      color: 'rgba(131,120,234,0.3)'
                    },
                    {
                      offset: 1,
                      color: 'rgba(131,120,234,0)'
                    }
                  ],
                  false
                ),
                shadowColor: 'rgba(131,120,234, 0.9)',
                shadowBlur: 20
              }
            },
            data: [502.84, 205.97, 332.79, 281.55, 398.35, 214.02]
          },
          {
            name: '销量统计',
            type: 'line',
            smooth: true, // 是否平滑
            showAllSymbol: true,
            symbol: 'circle',
            symbolSize: 25,
            lineStyle: {
              normal: {
                color: '#FB7293',
                shadowColor: 'rgba(0, 0, 0, .3)',
                shadowBlur: 0,
                shadowOffsetY: 5,
                shadowOffsetX: 5
              }
            },
            label: {
              show: true,
              position: 'top',
              textStyle: {
                color: '#00ca95'
              }
            },

            itemStyle: {
              color: '#ff9f7f',
              borderColor: '#fff',
              borderWidth: 3,
              shadowColor: 'rgba(0, 0, 0, .3)',
              shadowBlur: 0,
              shadowOffsetY: 2,
              shadowOffsetX: 2
            },
            tooltip: {
              show: false
            },
            areaStyle: {
              normal: {
                color: new Echarts.graphic.LinearGradient(
                  0,
                  0,
                  0,
                  1,
                  [
                    {
                      offset: 0,
                      color: 'rgba(230,144,209,0.3)'
                    },
                    {
                      offset: 1,
                      color: 'rgba(230,144,209,0)'
                    }
                  ],
                  false
                ),
                shadowColor: 'rgba(230,144,209, 0.9)',
                shadowBlur: 20
              }
            },
            data: [281.55, 398.35, 214.02, 179.55, 289.57, 356.14]
          }
        ]
      }
      // myChart.setOption(option)
      this.$emit('son', {
        myChart,
        option
      })
    }
  }
}
</script>

<style lang="less" scoped>
.content {
  margin-top: 40px;
  background-color: #fff;
  padding: 30px;
  box-sizing: border-box;
}
</style>
